#include <iostream>
#include <sstream>
#include <mono/parser/property_node.h>
#include <mono/parser/property_tree_printer.h>
#include <mono/parser/property_tree_parser.h>
using namespace mono;
int main(int argc, const char ** argv) {
	/*PropertyNode root("root");
	
	
	PropertyNode myNode("cool");
	myNode.addAttribute("attrib1");
	myNode.addProperty(Property("key", "value katt"));
	
	myNode.addNode(myNode);
	
	root.addNode(myNode);
	root.addNode(myNode);
	*/
	
	PropertyTreePrinter printer(std::cout);
	//printer.print(root);
	
	
	
	
	
	
	PropertyNodePtr base(new PropertyNode("root"));
	PropertyNodePtr myNode(new PropertyNode("www.vhost1..com"));
	myNode->addProperty(Property("p1", "v1"));
	myNode->addProperty(Property("p2", "v2"));
	myNode->addProperty(Property("p3", "v3"));
	myNode->addProperty(Property("p4", "v4"));
	myNode->addAttribute("attr1");
	myNode->addAttribute("attr2");
	myNode->addAttribute("attr3");
	myNode->addAttribute("attr4");

	PropertyNodePtr location1(new PropertyNode("/hello"));
	location1->addProperty(Property("/abc/def", "45 23v"));
	location1->addProperty(Property("/abc/def1", "45"));
	location1->addProperty(Property("/abc/def2", "45"));
	location1->addProperty(Property("/abc/def3", "45"));
	myNode->addNode(location1);
	base->addNode(myNode);
	printer.print(base);
	std::cout<<"**************************************************"<<std::endl;
	PropertyNodePtr location2(new PropertyNode("/big/test"));
	location2->addProperty(Property("speed_limit", "80M"));
	myNode->addNode(location2);
	printer.print(base);
	
	std::stringstream ss;
	PropertyTreePrinter newPrinter(ss);
	//newPrinter.print(newRoot, false);
	
	ss << "vhos1 a1 a2{ \n";
	ss << "   key \"valu e\" \n";
	ss << "//   key5 value5 \n";
	ss << "/*\n key3 value3 \n";
	ss << " key4 value4 \n */\n";
	ss << "#   key1 value1 \n";
	ss << "//   key2 value2 \n";
	ss << "} } \nvhost2 {key value\n}\n";
	
	std::cout << "SS: " << std::endl << ss.str() << std::endl;
	
	
	PropertyTreeParser parser;
	PropertyNodePtr createdTree = parser.parse(ss.str());
	if(createdTree) {
		std::cout << "parsed:" << std::endl;
		printer.print(createdTree);
	} else {
		std::cout << "parsed error" << std::endl;
	}
	
	return 0;
}
